/* @(#)GSProviderModifyAction.java    V0.1
 *
 * Project: GSdevelop
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   owen         2006-2-27
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package com.hitrust.gs.action;

import java.util.ArrayList;
import java.util.HashMap;

import org.apache.commons.beanutils.BeanUtils;

import system.LoginContext;

import client.XMLSend;

import com.hitrust.gs.bean.GSProviderBean;
import com.hitrust.gs.form.GSProviderModifyForm;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.service.GSBaseManager;
import com.hitrust.gs.util.exception.GSException;
import com.hitrust.gs.business.GSProviderProcessor;

import framework.core.Config;
import framework.core.ConstDefine;
import framework.core.DateUtil;
import framework.core.SrvContext;

/**
 * 修改供应商
 */
public class GSProviderModifyAction extends GSBaseAction{

    public String execute(GSBaseForm aForm) throws Exception {
        GSProviderModifyForm tForm = (GSProviderModifyForm)aForm;
        GSProviderBean tGSProviderBean=new GSProviderBean();
        BeanUtils.copyProperties(tGSProviderBean,tForm);
        SrvContext context = SrvContext.getContext(aForm.getRequest());
        LoginContext loginInfo = LoginContext.get(context);
        tGSProviderBean.setLast_update_user_id(loginInfo.getLoginUserId());
        tGSProviderBean.setLast_update_user(loginInfo.getLoginUserName());
        tGSProviderBean.setLast_update_time(new DateUtil().getFullString());
        try {
            GSProviderProcessor tProviderProcessor = new GSProviderProcessor();
            tProviderProcessor.modifyProvider(tGSProviderBean, tForm.getIsAudit(), loginInfo);
            
        } catch (GSException err) {
            if (err.getCode() != null) {
                HashMap tMap = new HashMap();
                tMap.put("err", err.getMessage());
                aForm.getRequest().setAttribute("_error", tMap);
                aForm.getRequest().setAttribute("message", err.getMessage());
                aForm.getRequest().setAttribute("exception_code", err.getCode());
                aForm.getRequest().setAttribute("requery", "true");
                aForm.getRequest().setAttribute("action", "A400101.do");
                throw err;
            }
        }
        if (XMLSend.getInstance().isToRong()) {
            String actionName = "SubmitProvider";
            String dataName = "Provider";
            // 传输xml to 荣爱
            XMLSend.getInstance().submitProviderSendXML(actionName, dataName, tGSProviderBean);

        }
        aForm.getRequest().setAttribute("message", "供应商信息修改成功!");
        aForm.getRequest().setAttribute("requery","true");
        
        //取得所有国家
        ArrayList tList = GSBaseManager.getAllCountry();
        aForm.getRequest().setAttribute("country",tList);
        //取得所有省
        tList = GSBaseManager.getAllProvince();
        aForm.getRequest().setAttribute("province",tList);
        //取得所有地区
        tList = GSBaseManager.getAllDistinct();
        aForm.getRequest().setAttribute("district",tList);
        //取得公司性质
        String[][] tStr= GSBaseManager.getAllCorpProperty();
        aForm.getRequest().setAttribute("corpproperty",tStr);
        return GSBaseConstants.FORWARD_SUCCESS;
    }

}
